package com.xzkydz.sensor.utils;

import android.text.TextUtils;
import android.util.Log;

/**
 *
 * @Description: log工具类
 * setLogDebug控制开关
 */
public class SensorLogger {
    private static final char TOP_LEFT_CORNER = '┌';
    private static final char BOTTOM_LEFT_CORNER = '└';
    private static final char HORIZONTAL_LINE = '│';
    private static final String DOUBLE_DIVIDER = "────────────────────────────────────────────────────────";
    private static final String TOP_BORDER = TOP_LEFT_CORNER + DOUBLE_DIVIDER + DOUBLE_DIVIDER;
    private static final String BOTTOM_BORDER = BOTTOM_LEFT_CORNER + DOUBLE_DIVIDER + DOUBLE_DIVIDER;

    private static final String LOG_TAG = "SensorLogger";
    /**
     * 日志开关
     */
    private static boolean LOG_DEBUG = true;

    public static void v(String text) {
        if (LOG_DEBUG && !TextUtils.isEmpty(text)) {
            Log.v(LOG_TAG, TOP_BORDER);
            Log.v(LOG_TAG, HORIZONTAL_LINE + " " + text);
            Log.v(LOG_TAG, BOTTOM_BORDER);
        }
    }

    public static void d(String text) {
        if (LOG_DEBUG && !TextUtils.isEmpty(text)) {
            Log.d(LOG_TAG, TOP_BORDER);
            Log.d(LOG_TAG, HORIZONTAL_LINE + " " + text);
            Log.d(LOG_TAG, BOTTOM_BORDER);
        }
    }

    public static void i(String text) {
        if (LOG_DEBUG && !TextUtils.isEmpty(text)) {
            Log.i(LOG_TAG, TOP_BORDER);
            Log.i(LOG_TAG, HORIZONTAL_LINE + " " + text);
            Log.i(LOG_TAG, BOTTOM_BORDER);
        }
    }

    public static void w(String text) {
        if (LOG_DEBUG && !TextUtils.isEmpty(text)) {
            Log.w(LOG_TAG, TOP_BORDER);
            Log.w(LOG_TAG, HORIZONTAL_LINE + " " + text);
            Log.w(LOG_TAG, BOTTOM_BORDER);
        }
    }

    public static void e(String text) {
        if (LOG_DEBUG && !TextUtils.isEmpty(text)) {
            Log.e(LOG_TAG, TOP_BORDER);
            Log.e(LOG_TAG, HORIZONTAL_LINE + " " + text);
            Log.e(LOG_TAG, BOTTOM_BORDER);
        }
    }

    /**
     * 设置Log开关
     * @param logDebug true打开 false关闭
     */
    public static void setLogDebug(boolean logDebug) {
        LOG_DEBUG = logDebug;
    }
}
